import type * as T from './type'
import http from '@/utils/http'

export type * from './type'

/**
 * 获取图片验证码
 */
export function getImageCaptcha() {
  return http.get<T.ImageCaptchaResp>(`/captcha/image`)
}

/**
 * 获取行为验证码
 * @param req
 */
export function getBehaviorCaptcha(req: any) {
  return http.get<T.BehaviorCaptchaResp>(`/captcha/behavior`, req)
}

/**
 * 校验行为验证码
 * @param req
 */
export function checkBehaviorCaptcha(req: any) {
  return http.post<T.CheckBehaviorCaptchaResp>(`/captcha/behavior/check`, req)
}

/**
 * 获取短信验证码
 * @param phone
 * @param captchaReq
 */
export function getSmsCaptcha(phone: string, captchaReq: T.BehaviorCaptchaReq) {
  return http.get<boolean>(`/captcha/sms?phone=${phone}&captchaVerification=${encodeURIComponent(captchaReq.captchaVerification || '')}`)
}

/**
 * 获取邮箱验证码
 * @param email
 * @param captchaReq
 */
export function getEmailCaptcha(email: string, captchaReq: T.BehaviorCaptchaReq) {
  return http.get<boolean>(`/captcha/mail?email=${email}&captchaVerification=${encodeURIComponent(captchaReq.captchaVerification || '')}`)
}
